# sandbox for ast...
import ast

source = '''s=s+x'''
node = ast.parse(source, mode='exec')
from pprint import pprint
pprint( ast.dump(node, annotate_fields=False, include_attributes=False) )  
#~ print (eval(compile(node, '<string>', mode='eval')))


"""
Module(
    body=[
        Assign(
            targets=[Name(id='s', ctx=Store())],
            value=BinOp(
                left=Name(id='s', ctx=Load()),
                op=Add(),
                right=Name(id='x', ctx=Load())
            )
        )
    ]
)
"""

def get_assignment_target(linecode):
    """
    >>> print( get_assignment_target("pinigai = laikas * atlyginimas") )
    pinigai
    """
    node = ast.parse(linecode, mode='exec')
    if (isinstance(node.body[0], ast.Assign)):
        assignment = node.body[0]
        return assignment.targets[0].id

#~ print( get_assignment_target("pinigai == laikas * atlyginimas") )
        
"""          
from ast import *
stmt = Module([Assign([Name('s', Store())], BinOp(Name('s', Load()), Add(), Name('x', Load())))])
print(isinstance(stmt, AST) )
print( getattr(stmt, 'body'))
if (isinstance(stmt.body[0], ast.Assign)):
    print("Assignment")
    assignment = stmt.body[0]
    print( stmt.body[0]._fields)
    print( assignment.targets[0].id )
#~ print (stmt['body'])
#~ if isinstance( stmt['body'] )
#~ print(stmt._fields[0]._fields)
"""
